<?php


namespace App\Http\Controllers\Warehouse;


use App\Http\Controllers\Controller;
use App\Http\Requests\Warehouse\PackageStock\StoreRequest;
use App\Repositories\ConsumableStock;
use App\Repositories\PackageStock;
use Illuminate\Support\Facades\DB;

class PackageStockController extends Controller
{
    /**
     * @var ConsumableStock
     * @author luffyzhao@vip.126.com
     */
    private $stock;

    /**
     * ConsumableStockController constructor.
     * @param PackageStock $stock
     * @author luffyzhao@vip.126.com
     */
    public function __construct(PackageStock $stock)
    {
        $this->stock = $stock;
    }

    /**
     * @param StoreRequest $request
     * @return \Illuminate\Http\JsonResponse
     * @author luffyzhao@vip.126.com
     */
    public function store(StoreRequest $request)
    {
        return $this->response(
            DB::transaction(function () use ($request) {
                $this->stock->create($request->only([
                    'package_id', 'type', 'stock', 'remark'
                ]));
            })
        );
    }
}